<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>复制功能测试</title>
</head>
<body>
    <h1>复制功能测试</h1>
    <p>测试链接: <span id="testUrl">https://example.com/test-image.jpg</span></p>
    <button onclick="testCopy()">📋 测试复制</button>
    
    <div id="result" style="margin-top: 20px; padding: 10px; border: 1px solid #ccc;"></div>

    <script>
        async function testCopy() {
            const text = document.getElementById('testUrl').textContent;
            const result = document.getElementById('result');
            
            result.innerHTML = '<p>正在测试复制功能...</p>';
            
            try {
                // 现代浏览器的剪贴板API
                if (navigator.clipboard && window.isSecureContext) {
                    await navigator.clipboard.writeText(text);
                    result.innerHTML = '<p style="color: green;">✅ 现代API复制成功！</p>';
                    return;
                }
            } catch (error) {
                result.innerHTML += '<p style="color: orange;">⚠️ 现代API失败: ' + error.message + '</p>';
            }

            try {
                // 降级方案
                const textArea = document.createElement('textarea');
                textArea.value = text;
                textArea.style.position = 'fixed';
                textArea.style.left = '-999999px';
                textArea.style.top = '-999999px';
                document.body.appendChild(textArea);
                textArea.focus();
                textArea.select();
                
                const successful = document.execCommand('copy');
                document.body.removeChild(textArea);
                
                if (successful) {
                    result.innerHTML += '<p style="color: green;">✅ 降级方案复制成功！</p>';
                } else {
                    throw new Error('execCommand返回false');
                }
            } catch (error) {
                result.innerHTML += '<p style="color: red;">❌ 降级方案失败: ' + error.message + '</p>';
                result.innerHTML += '<p style="color: blue;">💡 请手动复制: ' + text + '</p>';
            }
        }
    </script>
</body>
</html>